package se.gala.core.abstracts;

import se.gala.core.FixedOddsBet;

public abstract class GameWithFixedOdds extends AbstractGame {

	protected FixedOddsBet bet;	

	protected GameWithFixedOdds(int symbolCount, PrecisionDegree precision) {
		super(true);
		doInit(symbolCount, precision);
		doInitialDraw();
	}
	
	protected GameWithFixedOdds(long historicRNGSeed, int symbolCount, PrecisionDegree precision) {
		super(true, historicRNGSeed);
		doInit(symbolCount, precision);
		doInitialDraw();
	}
	
	protected GameWithFixedOdds(int symbolCount, PrecisionDegree precision, long historicRNGSeed) {
		super(true, historicRNGSeed);
		doInit(symbolCount, precision);
		doInitialDraw();
	}

	protected GameWithFixedOdds(int symbolCount) {
		super(true);
		doInit(symbolCount, PrecisionDegree.PRIMARY);
	}
	
	@Override
	public final void placeBet(AbstractBet bet) throws ClassCastException {
		if (bet instanceof FixedOddsBet) {
			placeBet((FixedOddsBet) bet);
		} else {
			throw new ClassCastException("Found: " + bet.getClass().getName()
					+ " when " + FixedOddsBet.class.getName() + " is expected");
		}
	}

	public final void placeBet(FixedOddsBet bet) {
		this.bet = bet;
		setGameId();
		resetWinning();
	}
	
	protected final void addToWinning(int amount) {
		winning += amount;
	}
	
	private final void resetWinning() {
		winning = 0;
	}

	private void doInit(int symbolCount, PrecisionDegree precision) {
		initSymbols(symbolCount, precision);
		setSymbols();
		ditributtedSymbolsProperlyInitialised();
	}
	
	protected abstract void doInitialDraw();
	
}
